﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace LayeredArchitectureSample.DomainModel
{
    internal class TripThatHasArrived : DomainObject, ITrip
    {
        private readonly ReadOnlyCollection<WareUnitsCounted> _wares;
        private readonly Route _route;

        public TripThatHasArrived(long id, IEnumerable<WareUnitsCounted> wares, Route route)
            : base(id)
        {
            if (wares == null) throw new ArgumentNullException("wares");
            if (route == null) throw new ArgumentNullException("route");

            if (route is UnspecifiedRoute)
            {
                throw new ArgumentException("Route must be specified");
            }

            _wares = new List<WareUnitsCounted>(wares).AsReadOnly();
            _route = route;
        }

        public ReadOnlyCollection<WareUnitsCounted> Wares
        {
            get { return _wares; }
        }

        public Route Route
        {
            get { return _route; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="route"></param>
        /// <param name="waresToTake"></param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException"></exception>
        /// <exception cref="ArgumentException"></exception>
        public void Ship(Route route, IEnumerable<WareUnitsCounted> waresToTake)
        {
            throw new InvalidOperationException("Cannot ship a trip that has already arrived");
        }

        /// <exception cref="InvalidOperationException"></exception>
        public void MarkAsArrivedToFinalDestination()
        {
            throw new InvalidOperationException("The trip has already arrived");
        }

        public string Status
        {
            get { return "Arrived"; }
        }

        public TripState State
        {
            get { return TripState.Arrived; }
        }
    }
}